/*     */ package com.kingdee.eas.lifetime.util.DButil;
/*     */ 
/*     */ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.dao.query.IQueryExecutor;
import com.kingdee.bos.dao.query.QueryExecutorFactory;
import com.kingdee.bos.dao.query.SQLExecutorFactory;
import com.kingdee.bos.metadata.MetaDataPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.query.PropertyUnitCollection;
import com.kingdee.bos.metadata.query.QueryFieldInfo;
import com.kingdee.bos.metadata.query.QueryInfo;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.eas.base.commonquery.ColumnItemData;
import com.kingdee.eas.lifetime.util.edcommonutils.EDcommonUtils;
import com.kingdee.eas.lifetime.util.edcommonutils.EDcommonUtils.StringUtils;
import com.kingdee.jdbc.rowset.IRowSet;
/*     */ 
/*     */ public class EDdbUtil
/*     */ {
/*  31 */   static final Logger logger = CoreUIObject.getLogger(EDdbUtil.class);
/*     */ 
/*     */   public static List execQuery(String sql)
/*     */     throws BOSException, SQLException
/*     */   {
/*  42 */     ArrayList result = new ArrayList();
/*  43 */     IRowSet rowSet = SQLExecutorFactory.getRemoteInstance(sql).executeSQL();
/*  44 */     ResultSetMetaData metaData = rowSet.getMetaData();
/*  45 */     int colCount = metaData.getColumnCount();
/*  46 */     while (rowSet.next()) {
/*  47 */       HashMap resMap = new HashMap();
/*  48 */       for (int i = 1; i <= colCount; i++) {
/*  49 */         String colName = metaData.getColumnName(i);
/*  50 */         resMap.put(colName, rowSet.getObject(i));
/*     */       }
/*  52 */       result.add(resMap);
/*     */     }
/*  54 */     return result;
/*     */   }
/*     */ 
/*     */   public static List execQueryInfo(String queryStr, EntityViewInfo viewInfo)
/*     */     throws BOSException, SQLException
/*     */   {
/*  68 */     IQueryExecutor executor = QueryExecutorFactory.getRemoteInstance(new MetaDataPK(queryStr));
/*  69 */     if (viewInfo != null) {
/*  70 */       executor.setObjectView(viewInfo);
/*     */     }
/*  72 */     return execQuery(executor.getSQL());
/*     */   }
/*     */ 
/*     */   public static List execQueryInfo(String queryStr, String oql)
/*     */     throws BOSException, SQLException
/*     */   {
/*  86 */     IQueryExecutor executor = QueryExecutorFactory.getRemoteInstance(new MetaDataPK(queryStr));
/*  87 */     if (!EDcommonUtils.StringUtils.isEmpty(oql)) {
/*  88 */       executor.setObjectView(oql);
/*     */     }
/*  90 */     return execQuery(executor.getSQL());
/*     */   }
/*     */ 
/*     */   public static HashMap getFieldFromQuery(QueryInfo queryInfo)
/*     */   {
/*  99 */     HashMap fieldMap = new HashMap();
/* 100 */     PropertyUnitCollection propertyUnitCollection = queryInfo.getUnits();
/* 101 */     if (propertyUnitCollection != null) {
/* 102 */       int size = propertyUnitCollection.size();
/* 103 */       for (int i = 0; i < size; i++) {
/* 104 */         if (!(propertyUnitCollection.get(i) instanceof QueryFieldInfo))
/*     */           continue;
/* 106 */         ColumnItemData item = new ColumnItemData();
/* 107 */         QueryFieldInfo queryFieldInfo = (QueryFieldInfo)propertyUnitCollection.get(i);
/* 108 */         item.setKey(queryFieldInfo.getName());
/* 109 */         item.setIndex(i);
/* 110 */         item.setTitle(queryFieldInfo.getDisplayName());
/* 111 */         String tempWidth = queryFieldInfo.getExtendedProperty("colWidthInKDTable");
/* 112 */         if ((tempWidth != null) && (!tempWidth.trim().equalsIgnoreCase("")))
/* 113 */           item.setWidth(Integer.valueOf(tempWidth).intValue());
/*     */         else
/* 115 */           item.setWidth(50);
/* 116 */         item.setHidden(!queryFieldInfo.isIsSelector());
/* 117 */         if ((!item.isHidden()) && (!StringUtils.isEmpty(item.getTitle())) && (!item.getTitle().equals("ID"))) {
/* 118 */           fieldMap.put(item.getKey(), item);
/*     */         }
/*     */       }
/*     */     }
/* 122 */     return fieldMap;
/*     */   }
/*     */ }

/* Location:           D:\work\kingdee\enable\富国基金\fuguo_lib.jar
 * Qualified Name:     com.kingdee.eas.lifetime.util.DButil.EDdbUtil
 * JD-Core Version:    0.6.0
 */